//跑的快比赛模式
module.exports.createRoom = function(roomId,channelService,GameRemote) {
	var basic = require("./hunanRunQuickly.js").createRoom
	var room = new basic(roomId,channelService,GameRemote)
	room.roomMode = "hunanRunQuicklyCompetition"
	room.beginMode = 3
	console.log("hunanRunQuicklyRoom!!!!")
	//设置游戏信息
	room.setBeforeInfo = function(info) {
		console.log("setBeforeInfo : ",info)
		room.numeration = info.numeration
		room.RoomIndex = info.RoomIndex
		room.curRound = info.curRound
		room.maxRound = info.maxRound
		room.cid = info.cid
		console.log("cid : ",room.cid)
	}
	room.setLaterInfo = function(info) {
		if(info.curRound >= info.maxRound || (info.importance && info.maxRound - info.curRound < 2)){
			//获取库存
			GameRemote.dbService.db.hget("game:competition:inventory",room.cid,function(err,data) {
				console.log("game:competition:inventory : ",data)
				var rate = 1
				if(!data || data <= 20){
					for(var i = 0;i < room.players.length;i++){
						if(room.players[i] && room.players[i].uid < 10000){
							room.luckys[i] = 80 * rate
							rate *= 0.2
						}
					}
				}else if(data > 60){
					for(var i = 0;i < room.players.length;i++){
						if(room.players[i] && room.players[i].uid > 10000){
							room.luckys[i] = Math.floor(Math.random() * 30)
						}else{
							room.luckys[i] = 0
						}
					}
				}else{
					for(var i = 0;i < room.players.length;i++){
						if(room.players[i] && room.players[i].uid < 10000){
							room.luckys[i] = 0
						}
					}
				}
				console.log("概率 : ",room.luckys)
			})
		}
	}
	room.joinLaterFun = function(chair) {
		if(room.players[chair].playerInfo.contorl){
			room.luckys[chair] = parseInt(room.players[chair].playerInfo.contorl)
		}
	}
	//游戏结束保存战绩
	room.gameOverBefore = function(win,scores) {
		var info = {
			win : room.players[win].uid,
			score : scores[win]
		}
		room.gameOver(info)
	}
	return room
}